package com.zjkj.mp.dao.message.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zjkj.mp.dao.DaoBase;
import com.zjkj.mp.dao.message.TemplateManagerDAO;
import com.zjkj.mp.utils.PaginatedResult;
import com.zjkj.mp.vo.messageManager.Template;
import com.zjkj.mp.vo.messageManager.TemplateCategory;
@Repository
public class TemplateManagerDAOImpl extends DaoBase implements TemplateManagerDAO {

	public int updateTemplateCat(TemplateCategory templateCategory)
			throws Exception {
		
		return this.getSqlMapClient().update("updateTemplateCat", templateCategory);
	}

	public void createTemplateCat(TemplateCategory templateCategory)
			throws Exception {
		this.getSqlMapClient().update("createTemplateCat", templateCategory);
	}

	public PaginatedResult findQueryRsult(Map map) throws Exception {
		PaginatedResult result = new PaginatedResult();
		int currentPage = (Integer) map.get("currentPage");
		Object obj = this.getSqlMapClient().queryForObject("findQueryRsultCount", map);
		int count = 0;
		if(obj != null){
			count = (Integer)obj ;
		}
		result.setTotalSize(count);
		List resultList = this.getSqlMapClient().queryForList("findQueryRsult", map, (currentPage-1)*10, 10);
		result.setResult(resultList);
		result.setCurrPage(currentPage);
		result.setPageSize(10);
		return result;
	}

	public PaginatedResult findAllQueryRsult(Map map) throws Exception {
		
		PaginatedResult result = new PaginatedResult();
		int currentPage = (Integer) map.get("currentPage");
		Object obj = this.getSqlMapClient().queryForObject("findAllQueryRsultCount", map);
		int count = 0;
		if(obj != null){
			count = (Integer)obj ;
		}
		result.setTotalSize(count);
		List resultList = this.getSqlMapClient().queryForList("findAllQueryRsult", map, (currentPage-1)*10, 10);
		result.setResult(resultList);
		result.setCurrPage(currentPage);
		result.setPageSize(10);
		return result;
	}

	public int updateTemplateCat(Map map) throws Exception {
		
		return this.getSqlMapClient().update("updateTemplateCatByParam", map);
	}

	public int deleteTempCat(Map map) throws Exception {
		
		return this.getSqlMapClient().update("deleteTempCat", map);
	}

	public List findAllType(Map map) throws Exception {
		List templateCategory = (List) this.getSqlMapClient().queryForList("findAllType", map);
		return templateCategory;
	}

	public int updateTemplate(Map map) throws Exception {
		
		return this.getSqlMapClient().update("updateTemplate", map);
	}

	public int createTemplate(Map map) throws Exception {
		
		return this.getSqlMapClient().update("createTemplate", map);
	}

	public PaginatedResult findAllTemplateList(Map map) throws Exception {
		PaginatedResult result = new PaginatedResult();
		int currentPage = (Integer) map.get("current");
		result.setCurrPage(currentPage);
		int count = (Integer) this.getSqlMapClient().queryForObject("findAllTemplateListCount", map);
		result.setTotalSize(count);
		List resultList = this.getSqlMapClient().queryForList("findAllTemplateList", map, (currentPage-1)*10, 10);
		result.setResult(resultList);
		return result;
	}

	public Template findTemplate(Map map) throws Exception {
		Template template = (Template) this.getSqlMapClient().queryForObject("findTemplate", map);
		return template;
	}

	public PaginatedResult findTemplateQueryResult(Map map)
			throws Exception {
		PaginatedResult result = new PaginatedResult();
		int currentPage = (Integer) map.get("currentPage");
		Object obj = this.getSqlMapClient().queryForObject("findTemplateQueryRsultCount", map);
		int count = 0;
		if(obj != null){
			count = (Integer)obj ;
		}
		result.setTotalSize(count);
		List resultList = this.getSqlMapClient().queryForList("findTemplateQueryRsult", map, (currentPage-1)*10, 10);
		result.setResult(resultList);
		result.setCurrPage(currentPage);
		result.setPageSize(10);
		return result;
	}

}

/**
 * Copyright © 2013,指尖科技 All rights reserved.
 */